<template>
    <view class="content">
        <view class="class1">
            <view class="top" v-if="data.enter_examine == 1">
                <image src="../../static/icon/wait.png" class="top-icon"></image>
                <view class="top-tit">待审核</view>
            </view>
            <view class="top" v-if="data.enter_examine == 2">
                <image src="../../static/icon/yx.png" class="top-icon"></image>
                <view class="top-tit">已通过</view>
            </view>
            <view class="top" v-if="data.enter_examine == 3">
                <image src="../../static/icon/wx.png" class="top-icon"></image>
                <view class="top-tit">认购无效</view>
            </view>
            <!-- <view class="box">
                <view class="wxyy">无效原因</view>
                <view class="wxyy-text">具体原因内容具体原因内容具体原因内容具体原因内容具体原因内容具体原因内容具体原因内容</view>
            </view> -->
            <view class="box">
                <view class="title2">报备信息</view>
                <view class="item">
                    <view class="item-l">客户姓名：</view>
                    <view class="u-flex-1">{{data.name}}</view>
                </view>
                <view class="item">
                    <view class="item-l">客户电话</view>
                    <!-- <view class="u-flex-1" v-if="!role">{{data.phone}}</view>
                    <view class="u-flex-1" v-if="role && data.phone">{{ data.phone.substring(0, 3)+"****"+data.phone.substring(7) }}</view> -->
                    <view class="u-flex-1">{{data.phone}}</view>
                </view>
                <view class="item">
                    <view class="item-l">客户性别</view>
                    <view class="u-flex-1">{{data.gender == 1 ? '男' : '女'}}</view>
                </view>
                <view class="item">
                    <view class="item-l">意向楼盘</view>
                    <view class="u-flex-1">{{data.pro_name}}</view>
                </view>
                <view class="item">
                    <view class="item-l">报备经纪人</view>
                    <view class="u-flex-1">{{data.broker_name}}</view>
                </view>
                <view class="item">
                    <view class="item-l">联系电话</view>
                    <view class="u-flex-1 u-flex">
                        <view class="u-flex-1">{{data.broker_phone}}</view>
                        <view class="btn-b" @click="doCall(data.broker_phone)">一键拨号</view>
                    </view>
                </view>
                <view class="item">
                    <view class="item-l">绑定机构</view>
                    <view class="u-flex-1">{{data.institution}}</view>
                </view>
                <view class="item">
                    <view class="item-l">所属门店</view>
                    <view class="u-flex-1">{{data.stores}}</view>
                </view>
                <template v-if="data.manager_name && data.enter_examine == 3">
                    <view class="item">
                        <view class="item-l">运维经理</view>
                        <view class="u-flex-1">{{data.manager_name}}</view>
                    </view>
                    <view class="item">
                        <view class="item-l">联系电话</view>
                        <view class="u-flex-1 u-flex">
                            <view class="u-flex-1">{{data.manager_phone}}</view>
                            <view class="btn-b" @click="doCall(data.manager_phone)">一键拨号</view>
                        </view>
                    </view>
                </template>
                <view class="item">
                    <view class="item-l">到访时间</view>
                    <view class="u-flex-1">{{data.visit_time}}</view>
                </view>
                <view class="item">
                    <view class="item-l">认购时间</view>
                    <view class="u-flex-1">{{data.buy_time}}</view>
                </view>
                <view class="item">
                    <view class="item-l">房源信息</view>
                    <view class="u-flex-1">
                        建面{{data.area}}㎡，总价{{data.all_price}}元，佣金{{data.commission}}{{data.commission_type == 2 ? '%' : '元'}}
                    </view>
                </view>
                
                <template v-if="data.enter_examine != 3">
                    <view class="border-t u-m-t-20 u-p-t-25" v-if="data.project_name">
                        <view class="item">
                            <view class="item-l">项目总监</view>
                            <view class="u-flex-1">{{data.project_name}}</view>
                        </view>
                        <view class="item">
                            <view class="item-l">联系电话</view>
                            <view class="u-flex-1 u-flex">
                                <view class="u-flex-1">{{data.project_phone}}</view>
                                <view class="btn-b" @click="doCall(data.project_phone)">一键拨号</view>
                            </view>
                        </view>
                    </view>
                    <view class="border-t u-m-t-20 u-p-t-25" v-if="data.resident_name">
                        <view class="item">
                            <view class="item-l">项目驻场</view>
                            <view class="u-flex-1">{{data.resident_name}}</view>
                        </view>
                        <view class="item">
                            <view class="item-l">联系电话</view>
                            <view class="u-flex-1 u-flex">
                                <view class="u-flex-1">{{data.resident_phone}}</view>
                                <view class="btn-b" @click="doCall(data.resident_phone)">一键拨号</view>
                            </view>
                        </view>
                    </view>
                    <view class="border-t u-m-t-20 u-p-t-25" v-if="data.manager_name">
                        <view class="item">
                            <view class="item-l">运维经理</view>
                            <view class="u-flex-1">{{data.manager_name}}</view>
                        </view>
                        <view class="item">
                            <view class="item-l">联系电话</view>
                            <view class="u-flex-1 u-flex">
                                <view class="u-flex-1">{{data.manager_phone}}</view>
                                <view class="btn-b" @click="doCall(data.manager_phone)">一键拨号</view>
                            </view>
                        </view>
                    </view>
                </template>
                
                <!-- <view class="border-t" v-if="data.buy_remark">
                    <view class="title">备注</view>
                    <textarea v-model="data.buy_remark" placeholder="输入备注" maxlength="200" disabled></textarea>
                </view> -->
                
                <view class="border-t u-m-t-20" v-if="data.annex_img && data.annex_img[0] && data.annex_img[0].image">
                    <view class="title">成交附件</view>
                    <view class="img-box">
                        <image :src="data.annex_img[0].image" class="up-photo" @click="doPreview(data.annex_img[0].image)"></image>
                    </view>
                </view>
                <view class="border-t u-m-t-20" v-if="data.visit_img && data.visit_img[0] && data.visit_img[0].image">
                    <view class="title">上传到访单</view>
                    <view class="img-box">
                        <image :src="data.visit_img[0].image" class="up-photo" @click="doPreview(data.visit_img[0].image)"></image>
                    </view>
                </view>
                <view class="border-t u-m-t-20" v-if="data.group_img && data.group_img[0] && data.group_img[0].image">
                    <view class="title">上传三方合影</view>
                    <view class="img-box">
                        <image :src="data.group_img[0].image" class="up-photo" @click="doPreview(data.group_img[0].image)"></image>
                    </view>
                </view>
                <view class="border-t u-m-t-20" v-if="data.buy_img && data.buy_img[0] && data.buy_img[0].image">
                    <view class="title">上传认购单</view>
                    <view class="img-box">
                        <image :src="data.buy_img[0].image" class="up-photo" @click="doPreview(data.buy_img[0].image)"></image>
                    </view>
                </view>
            </view>
            
            <!-- 订单轨迹 -->
            <view class="box" v-if="!role">
                <view class="title2">订单轨迹</view>
                <u-time-line>
                	<u-time-line-item v-for="(item, index) in data.order" :key="index">
                		<template v-slot:content>
                			<view>
                				<view class="context" :class="{active : index == 0}">{{item.msg}}</view>
                				<view class="u-order-time time">更新时间：{{item.time}}</view>
                			</view>
                		</template>
                	</u-time-line-item>
                </u-time-line>
            </view>
            
            <view class="btn" v-if="data.examine == 3 && !role" @click="$gTo('/pages/kehu/edit-subscribe?id=' + id + '&isEdit=1')">编辑</view>
            
            <!-- report == 2 没有审核按钮(只有 项目驻场 要判断) -->
            <!-- 个人中心 项目驻场审核，其他角色查看 -->
            <template v-if="(role == 3 && data.enter_examine == 1 && data.report != 2) || (role == 8 && data.enter_examine == 1 && !data.resident_name)">
                <view class="u-flex u-row-between u-m-b-20" style="width: 100%;">
                	<view class="btn1" @click="show = true">驳回</view>
                	<view class="btn2" @click="doExamine(2)">通过</view>
                </view>
            </template>
            <!-- 驳回原因弹窗 -->
            <u-mask :show="show" mode="center" border-radius="14">
                <view class="popup">
                    <view class="win-box2">
                        <view class="pop-cen">
                            <view class="pop-tit">驳回原因</view>
                            <textarea v-model="content" placeholder="请输入驳回原因" class="pop-text"></textarea>
                        </view>
                        <view class="pop-btn">
                            <view @click="show = false">取消</view>
                            <view @click="doExamine(3)">确认</view>
                        </view>
                    </view>
                </view>
            </u-mask>
        </view>  
    </view>
</template>

<script>
    import { API_URL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                noClick:true,//连点
                show: false,
                URL: API_URL, //上传图片用的
                fjImg: '',//成交附件
                fjImgId: '',
                // cwidth: '',//画布宽
                // cheight: '',//画布高
                urls: '',
                // urlsArr: [],
                // address: {},
                // latitude: '',
                // longitude: '',
                
                id: '',
                data: {},
                role: '',
                content: '',
            };
        },
        onLoad(option) {
            this.id = option.id
            // 从个人中心 项目报备列表进入
            if (option.role) {
                this.role = option.role
            }
            this.getData()
        },
        methods: {
			doCall(tel) {
				if (tel) {
					uni.makePhoneCall({
					    phoneNumber: tel
					});
				} else {
					this.$toast('暂无联系电话')
				}
			},
			
            // 审核 认购信息
            doExamine(num, item) {
                this.$ajax('reporting_examine', {
                    user_token: this.$getSync('userToken'),
                    id: this.id,//报备id
                    status: 4,//1报备 2到访 3认购 4认购信息 5结佣 6退户 7认证
                    examine: num,//2通过 3驳回
                    reason: this.content,//驳回原因
                }).then(ret => {
                    if (ret.success == 1000) {
                        this.show = false
                        this.$toast('提交成功');
                        setTimeout(() => {
                            this.$backT()
                        }, 500)
                    } else {
                        this.$toast(ret.msg);
                    }
                });
            },
            // 获取详情
            getData() {
                this.$ajax('reporting_detail', {
                    user_token: this.$getSync('userToken'),
                    id: this.id,//报备id
                }).then(ret => {
                    if (ret.success == 1000) {
                        this.data = ret.detail
                    } else {
                        this.$toast(ret.msg);
                    }
                });
            },
            
            // 预览图片
            doPreview(item) {
            	var arr = [];
                arr.push(item)
            	uni.previewImage({
            	    urls: arr,
            	    longPressActions: {
            	        success: function(data) {
            	        },
            	        fail: function(err) {
                            console.log(err)
            	        }
            	    }
            	});
            },
            
            // 上传图片
            chooseImg(num) {
                var _this = this
                uni.chooseImage({
                    count: 1, //默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 相机拍照 album 相册、camera 拍照
                    success: (res) => {
                        console.log('res',res)
                        _this.urls = res.tempFilePaths[0]
                        _this.uploadImg()
                    }
                });
            },
            // 上传
            uploadImg() {
                let _this = this
                uni.uploadFile({
                    url: _this.URL + 'api/upload_image', //仅为示例，并非真实接口地址。
                    filePath: _this.urls,
                    name: 'image',
                    formData:{module: 'api'},
                    success: result => {
                        console.log(result)
                        let data = JSON.parse(result.data).detail; //后台返回的路径data.attach_uri
                        _this.fjImg = data.image
                        _this.fjImgId = data.image_id
                    },
                    fail: err => {
                        console.log('err', err)
                    }
                });
            },
        }
    };
</script>

<style lang="scss">
    .btn1{
    	width: 332rpx;
    	height: 92rpx;
    	font-size: 34rpx;
    	line-height: 92rpx;
    	color: #000;
    	text-align: center;
    	border-radius: 46rpx;
    	background-color: #f0f0f0;
    }
    .btn2{
    	width: 332rpx;
    	height: 92rpx;
    	font-size: 34rpx;
    	line-height: 92rpx;
    	color: #fff;
    	text-align: center;
    	border-radius: 46rpx;
    	background-color: #00a1e9;
    }
    
    
    .popup {
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
    }
    .win-box2 {
        width: 80vw;
        background-color: #fff;
        border-radius: 20upx;
    }
    .pop-cen{
        padding: 50rpx 20rpx;
    }
    .pop-tit{
        font-size: 36rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 25rpx;
    }
    .pop-time{
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15rpx;
    }
    .pop-time-r{
        width: 55vw;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10rpx;
        border-radius: 10rpx;
        background-color: #f5f5f5;
    }
    .time-icon{
        width: 32rpx;
        height: 34rpx;
    }
    .pop-text{
        width: 100%;
        padding: 15rpx;
        border-radius: 10rpx;
        background-color: #f5f5f5;
        margin-top: 15rpx;
    }
    .pop-btn{
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-top: 2rpx solid #e6e6e6;
    }
    .pop-btn>view{
        width: calc(80vw / 2);
        text-align: center;
        padding: 35rpx 0;
        font-size: 30rpx;
        color: #00a1e9;
    }
    .pop-btn>view:first-child{
        border-right: 2rpx solid #e6e6e6;
    }
    
    textarea{
        width: 100%;
    }
    
    page{
        background-color: #f5f5f5;
    }
    .class1 {
        width: 100vw;
    	height: 400rpx;
    	background: linear-gradient(180deg, #3a9cf6, #3fafec, #f5f5f5);
        padding: 20rpx;
    }
    .top{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 0 0 35rpx 25rpx;
    }
    .top-icon{
        width: 69rpx;
        height: 69rpx;
        margin-right: 25rpx;
    }
    .top-tit{
        font-size: 42rpx;
        color: #fff;
    }
    
    .box{
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
        padding: 35rpx 30rpx;
    }
    .wxyy{
        font-size: 30rpx;
        color: #fe6155;
        padding-bottom: 10rpx;
    }
    .wxyy-text{
        font-size: 24rpx;
        word-break: break-all;
        white-space: pre-line;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
    }
    .name{
        font-size: 30rpx;
        font-weight: bold;
    }
    .item-l{
        width: 24.5vw;
    }
    .btn-b{
        padding: 15rpx 17rpx;
        border-radius: 10rpx;
        background-color: #ffecd2;
        font-size: 24rpx;
        line-height: 1;
        color: #803906;
        margin-left: 10rpx;
    }
    .border-t{
        border-top: 2rpx solid #e6e6e6;
    }
    .title{
        font-size: 28rpx;
        font-weight: bold;
        padding: 28rpx 0 20rpx;
    }
    .title2{
        font-size: 28rpx;
        font-weight: bold;
        padding-bottom: 20rpx;
    }
    .img-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .up-photo{
        width: 168rpx;
        height: 168rpx;
        margin-right: 15rpx;
        margin-bottom: 15rpx;
    }
    
    .context{
        font-size: 28rpx;
        font-weight: bold;
    }
    .active{
        color: #ff6539;
    }
    .time{
        font-size: 24rpx;
        color: #595959;
        padding-top: 5rpx;
    }
    
    .btn{
        color: #fff;
        font-size: 34rpx;
        text-align: center;
        padding: 25rpx;
        margin: 40rpx 0;
        background-color: #00a1e9;
        border-radius: 50rpx;
    }
    
</style>
